package rpc_server

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"middleware"
	"net"
	"protos/demo1_proto"
)

type server struct {
	demo1_proto.UnimplementedGreeterServer
}

func InitGrpc() {
	fmt.Println("server start")
	lis, _ := net.Listen("tcp", ":50001")
	s := grpc.NewServer(
		grpc.UnaryInterceptor(middleware.JWTInterceptor))
	demo1_proto.RegisterGreeterServer(s, &server{})
	s.Serve(lis)
}

func (s *server) Demo1Method(ctx context.Context, in *demo1_proto.HelloRequest) (*demo1_proto.HelloReply, error) {
	return &demo1_proto.HelloReply{Message: "Hello " + in.Name}, nil
}
